<template>
  <div id="mainDom" ref="mainDom" style="height: 350px; width: 100%"></div>
</template>

<script>
const echarts = require("echarts/lib/echarts");
require("echarts/lib/component/title");
require("echarts/lib/component/tooltip");
require("echarts/lib/component/grid");
require("echarts/lib/component/legend");
require("echarts/lib/chart/bar");
import { chome_inventory } from "@/apis/clientSide/Home/home";
export default {
  mounted() {
    this.$nextTick(() => {
      this.getInventoryDate();
    });
  },
  data() {
    return {
      SkuName: [],
      SkuValue: [],
    };
  },
  methods: {
    createChart() {
      //   var chartDom = ;
      var myChart = echarts.init(this.$refs.mainDom);
      var option;

      option = {
        title: {
          // text: 'World Population'
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        legend: {},
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
        },
        yAxis: {
          name: "单位：个",
          type: "category",
          data: this.SkuName,
        },
        series: [
          {
            type: "bar",
            data: this.SkuValue,
            itemStyle: {
              color: "#bc8dee",
            },
          },
        ],
      };

      option && myChart.setOption(option);
    },
    async getInventoryDate() {
      let res = await chome_inventory();
      if (res.code === "200") {
        this.SkuName = [];
        this.SkuValue = [];
        res.responseBody.forEach((item) => {
          this.SkuName.push(item.skuName);
          this.SkuValue.push(item.outboundNumber);
        });
        this.createChart();
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>